const app = getApp();
const https = require('../../utils/https');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 评分
    starCheckedImgUrl: '../../images/star1.png',
    starUnCheckedImgUrl: '../../images/star3.png',
    starMap: [
      '非常差',
      '差',
      '一般',
      '好',
      '非常好',
    ],
    starscores: [],
    service_start: 5,
    major_start: 5,
    clothing_start: 5,
    attitude_Start: 5,
    isShow: true,
    order_sn: '',
    loading: false,
    disabled: false,
  },
  // 产品评分
  chanageSeviceStart: function (obj) {
    var service_start = obj.currentTarget.dataset.star;
    this.setData({
      service_start: service_start
    })
  },
  chanageMajorStart: function (obj) {
    var major_start = obj.currentTarget.dataset.star;
    this.setData({
      major_start: major_start
    })
  },
  chanageClothingStart: function (obj) {
    var clothing_start = obj.currentTarget.dataset.star;
    this.setData({
      clothing_start: clothing_start
    })
  },
  chanageAttituedStart: function (obj) {
    var attitude_Start = obj.currentTarget.dataset.star;
    this.setData({
      attitude_Start: attitude_Start
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options && options.order_sn != '') {
      this.setData({
        order_sn: options.order_sn
      })
    }
  },

  //执行上传
  submit: function (obj) {
    var that = this,
      content = obj.detail.value['content'],
      service_start = this.data.service_start,
      major_start = this.data.major_start,
      clothing_start = this.data.clothing_start,
      attitude_Start = this.data.attitude_Start,
      user_id = wx.getStorageSync('user_id'),
      order_sn = this.data.order_sn;
    if (content == '') {
      wx.showToast({
        title: '请填写您的感受',
        icon: 'none',
        duration: 2000
      })
      return false;
    }
    that.setData({
      loading: true,
      disabled: true,
    })
    https.post('saveBookOrderCommon', {
      content: content,
      service_start: service_start,
      major_start: major_start,
      clothing_start: clothing_start,
      attitude_Start: attitude_Start,
      order_sn: order_sn,
      user_id: user_id,
    }, false, '正在保存').then(res => {
      wx.navigateBack({
        delta: 0,
      })
    })




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this,
      login_status = wx.getStorageSync('login_status');
    if (!login_status || login_status <= 0) {
      wx.showLoading({
        title: '请先进行登陆',
      })
      setTimeout(() => {
        wx.hideLoading({
          success: (res) => {
            wx.navigateTo({
              url: '/pages/grant/grant',
            })
          },
        })
      }, 1500);
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
})
